]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
bluetooth: Use BluetoothClient to detect connected devices
authorBastien Nocera <hadess@hadess.net>
Tue, 26 Nov 2013 13:46:13 +0000 (14:46 +0100)
committerBastien Nocera <hadess@hadess.net>
Tue, 26 Nov 2013 17:53:18 +0000 (18:53 +0100)
Instead of the GnomeBluetoothApplet helper.

https://bugzilla.gnome.org/show_bug.cgi?id=719341

js/ui/status/bluetooth.js

index 7a34f992b0215e95d5cbf9596c074fbaa9b2eb50..47171c7ff1aa51305c1cce95edd2cf5953ad62e0 100644 (file)
@@ -52,16 +52,45 @@ const Indicator = new Lang.Class({
         this._item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-bluetooth-panel.desktop');
         this.menu.addMenuItem(this._item);
 
-        this._applet = new GnomeBluetoothApplet.Applet();
-        this._applet.connect('devices-changed', Lang.bind(this, this._sync));
+        this._client = new GnomeBluetooth.Client();
+        this._model = this._client.get_model();
+        this._model.connect('row-changed', Lang.bind(this, this._sync));
+        this._model.connect('row-deleted', Lang.bind(this, this._sync));
+        this._model.connect('row-inserted', Lang.bind(this, this._sync));
         this._sync();
     },
 
+    _getDefaultAdapter: function() {
+        let [ret, iter] = this._model.get_iter_first();
+        while (ret) {
+            let isDefault = this._model.get_value(iter,
+                                                  GnomeBluetooth.Column.DEFAULT);
+            if (isDefault)
+                return iter;
+            ret = this._model.iter_next(iter);
+        }
+        return null;
+    },
+
+    _getNConnectedDevices: function() {
+        let adapter = this._getDefaultAdapter();
+        if (!adapter)
+            return 0;
+
+        let nDevices = 0;
+        let [ret, iter] = this._model.iter_children(adapter);
+        while (ret) {
+            let isConnected = this._model.get_value(iter,
+                                                    GnomeBluetooth.Column.CONNECTED);
+            if (isConnected)
+                nDevices++;
+            ret = this._model.iter_next(iter);
+        }
+        return nDevices;
+    },
+
     _sync: function() {
-        let connectedDevices = this._applet.get_devices().filter(function(device) {
-            return device.connected;
-        });
-        let nDevices = connectedDevices.length;
+        let nDevices = this._getNConnectedDevices();
 
         let on = nDevices > 0;
         this._indicator.visible = on;